Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@types/passport

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/passport

TypeScript definitions for Passport

  • 0.3.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.7M
increased by8.56%
Maintainers
1
Weekly downloads
 
Created

What is @types/passport?

The @types/passport npm package provides TypeScript type definitions for Passport.js, a popular authentication middleware for Node.js. These type definitions allow TypeScript developers to use Passport.js in their applications with the benefits of type safety and IntelliSense in their code editors.

What are @types/passport's main functionalities?

Authentication Middleware Initialization

This code initializes Passport as middleware in an Express application, enabling authentication functionalities.

import * as passport from 'passport';
app.use(passport.initialize());

Serialize User

This function defines how to store the user in the session storage, typically saving the user ID.

passport.serializeUser((user, done) => {
  done(null, user.id);
});

Deserialize User

This function defines how to retrieve the user from the session storage, using the user ID to fetch the user record from the database.

passport.deserializeUser((id, done) => {
  User.findById(id, (err, user) => {
    done(err, user);
  });
});

Use of Strategy

This code sample demonstrates how to implement a local authentication strategy using Passport.js. It involves checking the username and password against stored records.

import { Strategy as LocalStrategy } from 'passport-local';
passport.use(new LocalStrategy(
  function(username, password, done) {
    User.findOne({ username: username }, function (err, user) {
      if (err) { return done(err); }
      if (!user) { return done(null, false); }
      if (!user.verifyPassword(password)) { return done(null, false); }
      return done(null, user);
    });
  }
));

Other packages similar to @types/passport

FAQs

Package last updated on 25 Oct 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc